
export const conver2name = (tableMark, rowIndex) => {
    let _name = '';
    if (tableMark === 'main')
        _name = '主表';
    else {
        _name = rowIndex ? '明细' + tableMark.toString().substring(7) + `【行号:${parseInt(rowIndex) + 1}】` : '明细' + tableMark.toString().substring(7)
    }
    return _name;
}

export const singleConvert = (fieldid, fieldMap, showMark, rowIndex) => {
    let retStr = '';
    if (showMark) {
        retStr = fieldid;
    }
    else {
        if (fieldid.indexOf('_') == -1) {
            let fieldObj = fieldMap.get(fieldid);
            retStr = fieldObj && fieldObj.tableMark ? conver2name(fieldObj.tableMark, rowIndex) + '.' + fieldObj.fieldlabel : 'field' + fieldid;
        } else {
            fieldid = fieldid && fieldid.substring(0, fieldid.indexOf('_'));
            let fieldObj = fieldMap.get(fieldid);
            retStr = fieldObj && fieldObj.tableMark ? conver2name(fieldObj.tableMark, rowIndex) + '.' + fieldObj.fieldlabel : 'field' + fieldid;
        }
    }
    return retStr;
}

export const multiConvert = (fieldArr, fieldMap, showMark, rowIndex) => {
    let arr=[]
      fieldArr && fieldArr.map((fieldid,index) => {
        arr.push(<span className={index%2==1?"wf-heightLight":""}>{singleConvert(fieldid, fieldMap, showMark)}</span>)
    })
    return arr;
}

export const getRowIndex = (fieldMark) => {
    let retStr = null;
    if (fieldMark.indexOf('_') == -1) {
        retStr = '/';
    } else {
        retStr = parseInt(fieldMark.substring(fieldMark.indexOf('_') + 1)) + 1;
    }
    return retStr;
}

export const getStepType = (type) => {
    let retStr = '';
    switch (type) {
        case '1':
            retStr = '初始加载'
            break;
        case '2':
            retStr = '添加明细行'
            break;
        case '3':
            retStr = '手动变更'
            break;
        case '4':
            retStr = '同步联动'
            break;
        case '5':
            retStr = '异步联动'
            break;
        default:
            retStr = '接口修改'
    }
    return retStr;
}

export const getTriType = (type) => {
    let retStr = '';
    switch (type) {
        case 1:
            retStr = '字段值变化'
            break;
        case 2:
            retStr = '页面加载触发'
            break;
        case 3:
            retStr = '新增行触发'
            break;
        case 4:
            retStr = '删除行触发'
            break;
        case 'c_value':
            retStr = '字段值变更'
            break;
        case 'c_vars':
            retStr = '字段属性变更'
            break;
    }
    return retStr;
}

export const getLinkageType = (type) => {
    let retStr = '';
    if (type == 'fieldsql')
        retStr = 'SQL联动';
    else if (type == 'datainput')
        retStr = '字段联动';
    else
        retStr = '时间日期计算';
    return retStr;
}

export const getFieldid = (fieldMark) => {
    let retStr = null;
    if (fieldMark.indexOf('_') == -1) {
        retStr = fieldMark.substring(5);
    } else {
        retStr = fieldMark.substring(5, fieldMark.indexOf('_'));
    }
    return retStr;
}

export const doDuplicate = (dataArr) => {
    let retArr = [];
    retArr = dataArr.filter((x, index, arr) => {
        let trgFields = [];
        let assignFields = [];
        arr.forEach((item, i) => {
            trgFields.push(item.trgField)
            assignFields.push(item.assignField)
        })
        return trgFields.indexOf(x.trgField) === index && assignFields.indexOf(x.assignField) === index;
    })
    return retArr;
}